<!-- IF EDIT_POST -->
<form method="post" name="quick_edit" id="quick_edit{POST_ID}">
<textarea name="content" style="width:95%;" rows="10">{POST_TEXT}</textarea><br />
<input type="button" class="button2" onclick="ajax_edit_save({POST_ID});" value="{L_SAVE}" />
<input type="button" class="button2" onclick="ajax_edit_cancel({POST_ID});" value="{L_CANCEL}" />
</form>
<!-- ELSEIF SAVE_POST -->
{TEXT}
<!-- ELSE -->
<script type="text/javascript">
var cancel_posts = Array();
var edit_posts = Array();
var c_post_id = -1;
var c_menu = 0;
// <![CDATA[
function ajax_quick_edit(post_id)
{
	c_post_id = post_id;
	var div = document.getElementById("pb" + String(post_id));
	cancel_posts[post_id] = div.innerHTML;
	div.innerHTML = "{L_LOADING}";
	
	// Create new JsHttpRequest object.
	var req = new JsHttpRequest("utf-8");
	// Code automatically called on load finishing.
	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			if(req.responseJS && req.responseJS.success == true)
			{
				div.innerHTML = req.responseText;
			}
			else
			{
				ajax_message_box(req.responseText);
				document.getElementById("pb" + String(c_post_id)).innerHTML = cancel_posts[c_post_id]
				c_post_id = -1;
			}
		}
	}
	// Prepare request object
	req.open(null, 'aljax.php', true);
	// Send data to backend.
	req.send( {mode:'quick_edit',post_id:post_id} );
}

function ajax_edit_cancel(post_id)
{
	var div = document.getElementById("pb" + String(post_id));
	div.innerHTML = cancel_posts[post_id];
	c_post_id = -1;
}

function ajax_edit_save(post_id)
{
	var qe_form = document.getElementById("quick_edit" + String(post_id));
	var div = document.getElementById("pb" + String(post_id));
	edit_posts[post_id] = Array();
	edit_posts[post_id]['form'] = div.innerHTML;
	edit_posts[post_id]['post'] = qe_form.content.value;
	div.innerHTML = cancel_posts[post_id];
	
	div = document.getElementById("pc" + String(post_id));
	div.innerHTML = "{L_LOADING}";
	
	// Create new JsHttpRequest object.
	var req = new JsHttpRequest("utf-8");
	// Code automatically called on load finishing.
	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			if(req.responseJS && req.responseJS.success == true)
			{
				div.innerHTML = req.responseText;
			}
			else
			{
				ajax_message_box(req.responseText);
				document.getElementById("pb" + String(c_post_id)).innerHTML = edit_posts[c_post_id]['form'];
				document.getElementById("quick_edit" + String(post_id)).content.value = edit_posts[c_post_id]['post'];
			}
		}
	}
	// Prepare request object (automatically choose GET or POST).
	req.open('POST', 'aljax.php', true);
	// Send data to backend.
	req.send( {mode:'quick_edit',content:qe_form.content.value,post_id:post_id,submit:true} );
}

function ajax_quick_delete(post_id)
{
	if(confirm('{L_DELETE_MESSAGE_CONFIRM}'))
	{
		// Create new JsHttpRequest object.
		var req = new JsHttpRequest("utf-8");
		// Code automatically called on load finishing.
		req.onreadystatechange = function()
		{
			if (req.readyState == 4)
			{
				if(req.responseJS && req.responseJS.success == true)
				{
					ajax_message_box(req.responseText);
					var div = document.getElementById('p'+post_id);
					div.parentNode.removeChild(div);
				}
				else
				{
					ajax_message_box(req.responseText);
				}
			}
		}
		// Prepare request object (automatically choose GET or POST).
		req.open(null, 'aljax.php', true);
		// Send data to backend.
		req.send( {mode:'quick_delete',post_id:post_id} );
	}
}
function switch_menu(id)
{
	var menu_style = document.getElementById(id).style;
	if (menu_style.display != "block")
		c_menu.display = "none";
	c_menu = menu_style;
	if(menu_style.display != "block")
	{
		menu_style.display = "block";
	}
	else
	{
		menu_style.display = "none";
	}
}

// ]]>
</script>
<!-- ENDIF -->